package cn.edu.ujn.finaltest.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mysql.jdbc.StringUtils;

import cn.edu.ujn.finaltest.dao.ProductMapper;
import cn.edu.ujn.finaltest.util.Page;
import cn.edu.ujn.finaltest.dao.Orders;
import cn.edu.ujn.finaltest.dao.Product;

@Service
@Transactional
public class ProductServiceImpl implements IProductService{
	@Autowired
	private ProductMapper productdao;
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return this.productdao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Product row) {
		// TODO Auto-generated method stub
		return this.productdao.insert(row);
	}

	@Override
	public int insertSelective(Product row) {
		// TODO Auto-generated method stub
		return this.productdao.insertSelective(row);
	}

	@Override
	public Product selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return this.productdao.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Product row) {
		// TODO Auto-generated method stub
		return this.productdao.updateByPrimaryKeySelective(row);
	}

	@Override
	public int updateByPrimaryKey(Product row) {
		// TODO Auto-generated method stub
		return this.productdao.updateByPrimaryKey(row);
	}
    
	@Override
	public List<Product> findProductById(Integer id) {
		// TODO Auto-generated method stub
		return this.productdao.findProductById(id);
	}
	
	@Override
	public Page<Product> findProductList(Integer page, Integer rows, Integer id, String name,Integer price) {
		// TODO Auto-generated method stub
		
		Product product = new Product();
		product.setId(id);
		product.setPrice(price);
		if(!StringUtils.isNullOrEmpty(name)) {
			product.setName(name);
		}
		product.setStart((page-1) * rows);
		product.setRows(rows);
		List<Product> products = this.productdao.findAll(product);
		//查询客户列表总记录数
		Integer count = this.productdao.selectProductListCount(product);
		Page<Product> result = new Page<Product>();
		result.setPage(page);
		result.setRows(products);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}
	
	
	@Override
	public Integer selectProductListCount(Product product) {
		// TODO Auto-generated method stub
		return this.productdao.selectProductListCount(product);
	}
	
	@Override
	public List<Product> findAll(Product product){
		return this.productdao.findAll(product);
	}
}
